﻿//https://leetcode.cn/problems/container-with-most-water/
//暴力求解
class Solution {
public:
	int maxArea(vector<int>& height) {
		int n = height.size();
		int ret = 0;
		// 两层 for 枚举出所有可能出现的情况
		for (int i = 0; i < n; i++) {
			for (int j = i + 1; j < n; j++) {
				// 计算容积，找出最⼤的那⼀个
				ret = max(ret, min(height[i], height[j]) * (j - i));
			}
		}
		return ret;
	}
};

class Solution {
public:
    int maxArea(vector<int>& height) {
        int left = 0, right = height.size() - 1;
        int max = 0;
        while (left < right)
        {
            int h = (height[left] < height[right] ? height[left] : height[right]);
            int tmpv = h * (right - left);
            if (max < tmpv)
            {
                max = tmpv;
            }

            //更新
            if (height[left] < height[right])left++;
            else right--;
        }
        return max;
    }
};